From 42fed2490fe537b46a717eafaf1b1e4a5e0a08c8 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Tue, 18 Apr 2023 17:05:25 +0700
Subject: price tier

---
 src/pages/shop/product/[slug].jsx | 53 ++++++++++++++++++++++++---------------
 1 file changed, 33 insertions(+), 20 deletions(-)

(limited to 'src/pages/shop/product/[slug].jsx')

diff --git a/src/pages/shop/product/[slug].jsx b/src/pages/shop/product/[slug].jsx
index 84b848f0..230d1f87 100644
--- a/src/pages/shop/product/[slug].jsx
+++ b/src/pages/shop/product/[slug].jsx
@@ -1,48 +1,61 @@
 import Seo from '@/core/components/Seo'
+import LogoSpinner from '@/core/components/elements/Spinner/LogoSpinner'
 import { getIdFromSlug } from '@/core/utils/slug'
 import productApi from '@/lib/product/api/productApi'
 import dynamic from 'next/dynamic'
 import { useRouter } from 'next/router'
+import { useEffect, useState } from 'react'
 
 const BasicLayout = dynamic(() => import('@/core/components/layouts/BasicLayout'))
 const Product = dynamic(() => import('@/lib/product/components/Product/Product'))
 
-export async function getServerSideProps(context) {
-  const { slug } = context.query
-  let product = await productApi({ id: getIdFromSlug(slug) })
-  if (product?.length == 1) {
-    product = product[0]
-    const regexHtmlTags = /(<([^>]+)>)/gi
-    const regexHtmlTagsExceptP = /<\/?(?!p\b)[^>]*>/g
-    if (product.description.replace(regexHtmlTags, ' ').trim() == '') {
-      product.description = ''
+export default function ProductDetail() {
+  const router = useRouter()
+  const [product, setProduct] = useState(null)
+
+  useEffect(() => {
+    const { slug } = router.query
+
+    const loadProduct = async () => {
+      let product = await productApi({ id: getIdFromSlug(slug) })
+      if (product?.length == 1) {
+        product = product[0]
+        const regexHtmlTags = /(<([^>]+)>)/gi
+        const regexHtmlTagsExceptP = /<\/?(?!p\b)[^>]*>/g
+        if (product.description.replace(regexHtmlTags, ' ').trim() == '') {
+          product.description = ''
+        }
+        product.description = product.description.replace(regexHtmlTagsExceptP, ' ')
+        product.description = product.description.trim()
+      }
+      setProduct(product)
     }
-    product.description = product.description.replace(regexHtmlTagsExceptP, ' ')
-    product.description = product.description.trim()
-  }
-  return { props: { product } }
-}
+    if (slug) loadProduct()
+  }, [router])
 
-export default function ProductDetail({ product }) {
-  const router = useRouter()
   return (
     <BasicLayout>
       <Seo
-        title={product?.name + ' - Indoteknik.com' || ''}
+        title={product?.name || '' + ' - Indoteknik.com' || ''}
         description='Temukan pilihan produk B2B Industri &amp; Alat Teknik untuk Perusahaan, UMKM &amp; Pemerintah dengan lengkap, mudah dan transparan.'
         openGraph={{
           url: process.env.NEXT_PUBLIC_SELF_HOST + router.asPath,
-          image: product.image,
+          image: product?.image,
           type: 'product'
         }}
         additionalMetaTags={[
           {
             name: 'keywords',
-            content: `${product.name}, Harga ${product.name}, Beli ${product.name}, Spesifikasi ${product.name}`
+            content: `${product?.name}, Harga ${product?.name}, Beli ${product?.name}, Spesifikasi ${product?.name}`
           }
         ]}
       />
-      <Product product={product} />
+      {!product && (
+        <div className="container mx-auto flex justify-center pt-10">
+          <LogoSpinner width={36} height={36} />
+        </div>
+      )}
+      {product && <Product product={product} />}
     </BasicLayout>
   )
 }
-- 
cgit v1.2.3


From db5d67db219a6672848115b556fd572cdba7c60c Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Tue, 2 May 2023 15:14:18 +0700
Subject: fix product

---
 src/pages/shop/product/[slug].jsx | 45 ++++++++++++++++++++-------------------
 1 file changed, 23 insertions(+), 22 deletions(-)

(limited to 'src/pages/shop/product/[slug].jsx')

diff --git a/src/pages/shop/product/[slug].jsx b/src/pages/shop/product/[slug].jsx
index 230d1f87..7ab0ef76 100644
--- a/src/pages/shop/product/[slug].jsx
+++ b/src/pages/shop/product/[slug].jsx
@@ -9,29 +9,30 @@ import { useEffect, useState } from 'react'
 const BasicLayout = dynamic(() => import('@/core/components/layouts/BasicLayout'))
 const Product = dynamic(() => import('@/lib/product/components/Product/Product'))
 
-export default function ProductDetail() {
-  const router = useRouter()
-  const [product, setProduct] = useState(null)
+export async function getServerSideProps(context) {
+  const { slug } = context.query
+  
+  let product = await productApi({ id: getIdFromSlug(slug) })
+  if (product?.length == 1) {
+    product = product[0]
+    const regexHtmlTags = /(<([^>]+)>)/gi
+    const regexHtmlTagsExceptP = /<\/?(?!p\b)[^>]*>/g
+    if (product.description.replace(regexHtmlTags, ' ').trim() == '') {
+      product.description = ''
+    }
+    product.description = product.description.replace(regexHtmlTagsExceptP, ' ')
+    product.description = product.description.trim()
+  } else {
+    product = null
+  }
 
-  useEffect(() => {
-    const { slug } = router.query
+  return {
+    props: { product }
+  }
+}
 
-    const loadProduct = async () => {
-      let product = await productApi({ id: getIdFromSlug(slug) })
-      if (product?.length == 1) {
-        product = product[0]
-        const regexHtmlTags = /(<([^>]+)>)/gi
-        const regexHtmlTagsExceptP = /<\/?(?!p\b)[^>]*>/g
-        if (product.description.replace(regexHtmlTags, ' ').trim() == '') {
-          product.description = ''
-        }
-        product.description = product.description.replace(regexHtmlTagsExceptP, ' ')
-        product.description = product.description.trim()
-      }
-      setProduct(product)
-    }
-    if (slug) loadProduct()
-  }, [router])
+export default function ProductDetail({ product }) {
+  const router = useRouter()
 
   return (
     <BasicLayout>
@@ -51,7 +52,7 @@ export default function ProductDetail() {
         ]}
       />
       {!product && (
-        <div className="container mx-auto flex justify-center pt-10">
+        <div className='container mx-auto flex justify-center pt-10'>
           <LogoSpinner width={36} height={36} />
         </div>
       )}
-- 
cgit v1.2.3


From b4abdb00ef83aa824e8a05d5b75df48adb7b9629 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Wed, 3 May 2023 10:38:52 +0700
Subject: semi dynamic page

---
 src/pages/shop/product/[slug].jsx | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

(limited to 'src/pages/shop/product/[slug].jsx')

diff --git a/src/pages/shop/product/[slug].jsx b/src/pages/shop/product/[slug].jsx
index 7ab0ef76..ed6c27d5 100644
--- a/src/pages/shop/product/[slug].jsx
+++ b/src/pages/shop/product/[slug].jsx
@@ -4,24 +4,22 @@ import { getIdFromSlug } from '@/core/utils/slug'
 import productApi from '@/lib/product/api/productApi'
 import dynamic from 'next/dynamic'
 import { useRouter } from 'next/router'
-import { useEffect, useState } from 'react'
 
 const BasicLayout = dynamic(() => import('@/core/components/layouts/BasicLayout'))
 const Product = dynamic(() => import('@/lib/product/components/Product/Product'))
 
 export async function getServerSideProps(context) {
   const { slug } = context.query
-  
+
   let product = await productApi({ id: getIdFromSlug(slug) })
   if (product?.length == 1) {
     product = product[0]
     const regexHtmlTags = /(<([^>]+)>)/gi
     const regexHtmlTagsExceptP = /<\/?(?!p\b)[^>]*>/g
-    if (product.description.replace(regexHtmlTags, ' ').trim() == '') {
-      product.description = ''
-    }
-    product.description = product.description.replace(regexHtmlTagsExceptP, ' ')
-    product.description = product.description.trim()
+    product.description = product.description
+      .replace(regexHtmlTagsExceptP, ' ')
+      .replace(regexHtmlTags, ' ')
+      .trim()
   } else {
     product = null
   }
-- 
cgit v1.2.3


From baa7cb664e662cee23cdad92c78d9c14cab2445d Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Wed, 3 May 2023 15:19:35 +0700
Subject: add whatsapp widget and page not found

---
 src/pages/shop/product/[slug].jsx | 3 +++
 1 file changed, 3 insertions(+)

(limited to 'src/pages/shop/product/[slug].jsx')

diff --git a/src/pages/shop/product/[slug].jsx b/src/pages/shop/product/[slug].jsx
index ed6c27d5..cdba90c0 100644
--- a/src/pages/shop/product/[slug].jsx
+++ b/src/pages/shop/product/[slug].jsx
@@ -2,6 +2,7 @@ import Seo from '@/core/components/Seo'
 import LogoSpinner from '@/core/components/elements/Spinner/LogoSpinner'
 import { getIdFromSlug } from '@/core/utils/slug'
 import productApi from '@/lib/product/api/productApi'
+import PageNotFound from '@/pages/404'
 import dynamic from 'next/dynamic'
 import { useRouter } from 'next/router'
 
@@ -32,6 +33,8 @@ export async function getServerSideProps(context) {
 export default function ProductDetail({ product }) {
   const router = useRouter()
 
+  if (!product) return <PageNotFound />
+
   return (
     <BasicLayout>
       <Seo
-- 
cgit v1.2.3


From adf52ef6588def76e184ea04b6c6024d71b927c9 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Thu, 4 May 2023 10:18:24 +0700
Subject: fixing share product with product image

---
 src/pages/shop/product/[slug].jsx | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

(limited to 'src/pages/shop/product/[slug].jsx')

diff --git a/src/pages/shop/product/[slug].jsx b/src/pages/shop/product/[slug].jsx
index cdba90c0..290529a7 100644
--- a/src/pages/shop/product/[slug].jsx
+++ b/src/pages/shop/product/[slug].jsx
@@ -42,7 +42,14 @@ export default function ProductDetail({ product }) {
         description='Temukan pilihan produk B2B Industri &amp; Alat Teknik untuk Perusahaan, UMKM &amp; Pemerintah dengan lengkap, mudah dan transparan.'
         openGraph={{
           url: process.env.NEXT_PUBLIC_SELF_HOST + router.asPath,
-          image: product?.image,
+          images: [
+            {
+              url: product?.image,
+              width: 800,
+              height: 800,
+              alt: product?.name,
+            },
+          ],
           type: 'product'
         }}
         additionalMetaTags={[
-- 
cgit v1.2.3


From 598815af1ca2c7b549a867f3673c127af3ea9deb Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Thu, 4 May 2023 13:17:22 +0700
Subject: product get server side with user token

---
 src/pages/shop/product/[slug].jsx | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

(limited to 'src/pages/shop/product/[slug].jsx')

diff --git a/src/pages/shop/product/[slug].jsx b/src/pages/shop/product/[slug].jsx
index 290529a7..5d706dec 100644
--- a/src/pages/shop/product/[slug].jsx
+++ b/src/pages/shop/product/[slug].jsx
@@ -5,14 +5,19 @@ import productApi from '@/lib/product/api/productApi'
 import PageNotFound from '@/pages/404'
 import dynamic from 'next/dynamic'
 import { useRouter } from 'next/router'
+import cookie from 'cookie'
 
 const BasicLayout = dynamic(() => import('@/core/components/layouts/BasicLayout'))
 const Product = dynamic(() => import('@/lib/product/components/Product/Product'))
 
 export async function getServerSideProps(context) {
   const { slug } = context.query
+  const cookies = context.req.headers.cookie
+  const cookieObj = cookies ? cookie.parse(cookies) : {}
+  const auth = cookieObj.auth ? JSON.parse(cookieObj.auth) : {}
+  const authToken = auth?.token || ''
 
-  let product = await productApi({ id: getIdFromSlug(slug) })
+  let product = await productApi({ id: getIdFromSlug(slug), headers: { Token: authToken } })
   if (product?.length == 1) {
     product = product[0]
     const regexHtmlTags = /(<([^>]+)>)/gi
@@ -47,8 +52,8 @@ export default function ProductDetail({ product }) {
               url: product?.image,
               width: 800,
               height: 800,
-              alt: product?.name,
-            },
+              alt: product?.name
+            }
           ],
           type: 'product'
         }}
-- 
cgit v1.2.3

